﻿using System;
using System.Collections.ObjectModel;
using System.Linq;

using OpenCvSharp;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    [Filter("绘制点信息", FilterType.Draw)]
    public class DrawKeypoints : FilterBase
    {
        private ObservableCollection<CVKeyPoint> cVKeyPoint = new ObservableCollection<CVKeyPoint>();

        /// <summary>
        /// 颜色
        /// </summary>
        [InputParameter("颜色")]
        public Scalar Color { get; set; }
        /// <summary>
        /// 匹配标志
        /// </summary>
        [InputParameter("绘制模式")]
        public DrawMatchesFlags DrawMatchesFlags { get; set; }
        /// <summary>
        /// 坐标信息
        /// </summary>
        [InputParameter("坐标信息")]
        public ObservableCollection<CVKeyPoint> CVKeyPoint
        {
            get => cVKeyPoint; set
            {
                cVKeyPoint = value;
                RaisedPropertyChanged();
            }
        }    

        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterInfos, FilterBase preFilterBase)
        {
            Mat mat1 = new Mat();
            var d = CVKeyPoint.Select(p => (KeyPoint)p).ToArray();
            Cv2.DrawKeypoints(mat, d, mat1, Color, DrawMatchesFlags);
            return ResultData<Mat>.Accept(TextResource.filter_action_complete, mat1);
        }
    }

}
